/*
 * FreeBlocksFile.h
 *
 *  Created on: Oct 20, 2012
 *      Author: m
 */

#ifndef FREEBLOCKSFILE_H_
#define FREEBLOCKSFILE_H_

#include <fstream>
#include <string>
#include <unistd.h>
#include "physical_layer_commons.h"

namespace physical
{

class FreeBlocksFile
{
private:
    static const openmode defaulOpenmode;
    std::fstream m_freeBlocksSource;
    std::string m_fileName;

public:
    FreeBlocksFile( const char fileName[] );
    virtual ~FreeBlocksFile();

    blockNumber getFreeBlockNumber();
    void freeBlock( blockNumber id );
    bool hasFreeBlocks();

private:
    size_t getFileSize();
    bool truncateFile();
    void open();
};

}
#endif /* FREEBLOCKSFILE_H_ */
